#include "stm32f10x.h"                  // Device header

uint16_t my_size;

void myDMA_Init(uint32_t Adrr_A, uint32_t Adrr_B, uint16_t Size)
{
	my_size = Size;
	
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
	
	DMA_InitTypeDef myDMA_InitStructure;
	myDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	myDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
	myDMA_InitStructure.DMA_PeripheralBaseAddr = Adrr_A;			// 传入A的地址,我们一般不写绝对地址
	myDMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;
	myDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	myDMA_InitStructure.DMA_MemoryBaseAddr = Adrr_B;
	myDMA_InitStructure.DMA_BufferSize = Size;						// 就是传输次数的意思
	myDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
	myDMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
	myDMA_InitStructure.DMA_Mode = DMA_Mode_Normal ;				// 不能在 内存->内存 操作时开启循环模式
	myDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
	DMA_Init(DMA1_Channel1, &myDMA_InitStructure);
	
	DMA_Cmd(DMA1_Channel1, DISABLE);
}

void myDMA_Transfer(void)
{
	// 在修改传输次数size之前,先关闭DMA_Cmd
	DMA_Cmd(DMA1_Channel1, DISABLE);
	DMA_SetCurrDataCounter(DMA1_Channel1, my_size);
	DMA_Cmd(DMA1_Channel1, ENABLE);
}
